<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>照片墙</title>
    <style>
        div {
            margin: 0;
            padding: 0;
        }
        
        #entirety {
            position: relative;
            width: 509px;
            height: 509px;
            background-color: #F1F1F1;
        }
        
        .unit {
            width: 50px;
            height: 50px;
            background-image: url('./img/pic.jpg');
            background-repeat: no-repeat;
            opacity: 0;
        }
    </style>
</head>

<body>
    <div id="entirety">
    </div>
    <script>
        var entirety = document.getElementById('entirety');
        var units = entirety.getElementsByTagName('div');
        var poiTop = 0,
            poiLeft = 0,
            i = 0,
            j = 0;
        for (; i < 100; i++) {
            if (j == 10) {
                break;
            }
            if (i % 10 == 0 && i !== 0) {
                j++;
                poiTop += 51;
            }
            poiLeft = i % 10 * 50 + i % 10;
            entirety.innerHTML += '<div class="unit" style="position: absolute; left: ' + poiLeft + 'px; top: ' + poiTop + 'px; background-position: -' + poiLeft + 'px -' + poiTop + 'px;"></div>';
        }
        for (var k = 0; k < units.length; k++) {
            units[k].onmouseenter = function() {
                this.style.opacity = 1;
            }
        }
    </script>
</body>

</html>